import math


def prime_number(number):
    for j in range(2, int(math.sqrt(number)) + 1):
        if number % j == 0:
            return 0


number = int(input())
first_digit = number // 1000
second_digit = number // 100 % 10
third_digit = number // 10 % 10
fourth_digit = number % 10
if number <= 999 or number >= 10000:
    print(0)
elif prime_number(number) == 0:
    if prime_number(first_digit * 100 + second_digit * 10 + third_digit) == 0:
        if prime_number(first_digit * 100 + second_digit) == 0:
            if prime_number(first_digit) == 0 or first_digit == 1:
                print(0)
            else:
                print(first_digit)
        else:
            print(first_digit * 10 + d)
    else:
        print(first_digit * 100 + second_digit * 10 + third_digit)
else:
    print(number)
